package tinycloud;


import tinycloud.gui.frame.MainFrame;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import tinycloud.db.Database;


/**
 * Class principale de l'application.
 * @author Nicolas CHARREL
 */
public class TinyCloud {
    public static void main(String[] args) {
        Database db;
        db = new Database();
        
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TinyCloud.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(TinyCloud.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(TinyCloud.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(TinyCloud.class.getName()).log(Level.SEVERE, null, ex);
        }
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MainFrame mainJFrame = new MainFrame();
            }
        });  
    }

    public static void initDb() {
        Connection c;
        
        try {

            Statement s = c.createStatement();
            s.executeUpdate("CREATE TABLE directories (filename VARCHAR(500), d BIGINT)");
            s.executeUpdate("CREATE TABLE options (name VARCHAR(500), value VARCHAR(500))");
            s.executeUpdate("INSERT INTO options VALUES ('server', 'http://exemple.com')");
            s.executeUpdate("INSERT INTO options VALUES ('port', 'mon port')");
            s.executeUpdate("INSERT INTO options VALUES ('username', 'mon nom')");
            s.executeUpdate("INSERT INTO options VALUES ('password', 'mon mot de passe')");
            s.executeQuery("SHUTDOWN");
            s.close();
            c.close();
        } catch (Exception ex) {
            System.out.print(ex);
        }
    }
}
